﻿using System;
using Kiva7.Utilities;
using Kiva7.DataResponse;
using Kiva7.DataClasses;

namespace Kiva7.DataRequests
{
    public class LenderLoansRequest : DataRequest<LoansResponse, Loan>
    {
        public LenderLoansRequest()
            : base(true, true)
        {
        }


        public Uri BuildUri(string lenderId, SortBy sortBy)
        {
            UrlCreator url = new UrlCreator(string.Format(BaseUrl + "lenders/{0}/loans.xml", lenderId));

            if (sortBy == SortBy.Oldest)
            {
                url.Add("sort_by", "oldest");
            }
            else
            {
                url.Add("sort_by", "newest");
            }
            url.Add("app_id", KivaAppId);

            return url.ToUri();
        }


        internal void GetLoans(string lenderId, SortBy sortBy)
        {
            base.LoadResponse(BuildUri(lenderId, sortBy));
        }
    }

}
